
#make you own Exception
#__metaclass__ = type
# class SomeCostumException(Exception):
# 	pass

#raise Exception
#raise SomeCostumException
#from exceptions import ZeroDivisionError


# try:
# 	x = input("Enter the first number: ")
# 	y = input("Enter the second number: ")
# 	print x/y
# except (ZeroDivisionError), e:
# 	print "dee buffff"
# 	print e
# 	raise e


# MuffledCalculator Example

# class MuffledCalculator():
# 	"""docstring for MuffledCalculator"""
# 	def __init__(self, muffled = True):
# 		#super(MuffledCalculator, self).__init__()
# 		self.muffled = muffled;
# 	def calc(self,expr):
# 		try:
# 			return eval(expr)
# 		except ZeroDivisionError, e:
# 			if self.muffled:
# 				print "Division by Zero is illegal"
# 			else:
# 				raise

# calcu = MuffledCalculator();
# calcu.calc("1+1")
# calcu.muffled = True;
# calcu.calc("1/0")
# calcu.muffled = False;
# calcu.calc("1/0")


# many Except for many error

# try:
# 	x = input("Enter the first number: ")
# 	y = input("Enter the second number: ")
# 	print x/y
# except ZeroDivisionError, e:
# 	print "dee buffff"
# 	print e
# 	raise e
# except TypeError,e:
# 	print "TypeError "

#use matatable to except many error

# try:
# 	x = input("Enter the first number: ")
# 	y = input("Enter the second number: ")
# 	print x/y
# except (TypeError,ZeroDivisionError), e:
# 	print "dee buffff"
# 	print e
# 	raise e


#---- real catch all error but not recommand

# try:
# 	x = input("Enter the first number: ")
# 	y = input("Enter the second number: ")
# 	print x/y
# except:
# 	print "dee buffff"

#---- try&execpt&else

# try:
# 	print "this is a small task"
# except Exception, e:
# 	print "this is something wrong"
# else:
# 	print "the small task has done without error"
# finally:
# 	print "no matter, call it a day "

#---- a loop to reask user to type in number to calculate when error occor

# while True:
# 	try:
# 	    x = input("Enter the first number: ")
# 	    y = input("Enter the second number: ")
# 	    value = x/y
# 	    print "x/y is",value	
# 	except Exception, e:
# 		print	"invalid input , Please try again"
# 	else:
# 		break
# 	finally:
# 		print "no matter, call it a day "

#---- a loop to reask user to type in number to calculate when error occor
#---- and use exception to print more useful info

# while True:
# 	try:
# 	    x = input("Enter the first number: ")
# 	    y = input("Enter the second number: ")
# 	    value = x/y
# 	    print "x/y is",value	
# 	except Exception, e:
# 		print	e;
# 		print	"invalid input , Please try again"
# 	else:
# 		break
# 	finally:
# 		print "no matter, call it a day "

#---- Exception and Function   excetion traceback to main func()

# def faulty():
# 	raise	Exception("something is wrong")

# def ignore_exception():
# 	faulty();
# def handle_exception():
# 	try:
# 		faulty()
# 	except:
# 		print "exception handled"
# ignore_exception();


#----leap before you look

# def describePerson(person):
# 	print "Description of", person['name']
# 	print "Age", person['Age']
# 	print "Occupation:" +person["occupation"]



# person1 = {'name':"haha","Age":18};
# describePerson(person1);



# def describePerson(person):
# 	print "Description of", person['name']
# 	print "Age", person['Age']
# 	try:
# 		print "Occupation:" +person["occupation"]
# 	except KeyError:
# 		pass


# person1 = {'name':"haha","Age":18};
# describePerson(person1);

#---- another way to getattr


# try:
# 	obj.write
# except Exception, e:
#     print "the object is not writeable"
# else:
# 	print "the object is writeable"
# finally:
# 	pass